package com.muqi.app.user.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.muqi.app.qlearn.student.R;

public class MineInfoEntryText extends RelativeLayout {
	private TextView title;
	private EditText name;
	private ImageView icon;
	private boolean isShow;
	private boolean isEdit;

	public MineInfoEntryText(Context context) {
		super(context);
		init(context, null);
	}

	public MineInfoEntryText(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context, attrs);
	}

	public MineInfoEntryText(Context context, AttributeSet attrs,
			int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		init(context, attrs);
	}

	private void init(Context context, AttributeSet attrs) {
		LayoutInflater inflater = LayoutInflater.from(context);
		View view = inflater.inflate(R.layout.mine_info_entry_text, this, true);
		name = (EditText) view.findViewById(R.id.name);
		title = (TextView) view.findViewById(R.id.title);
		icon = (ImageView) view.findViewById(R.id.icon);
		// 通过上下文context获取自定义属性
		TypedArray typeArr = context.obtainStyledAttributes(attrs,
				R.styleable.MineEntryText);
		// 获取在xml文件中,自定义属性的值
		if (typeArr != null) {
			isEdit = typeArr.getBoolean(
					R.styleable.MineEntryText_mine_isEditable, false);
			isShow = typeArr.getBoolean(
					R.styleable.MineEntryText_mine_isShowNext, true);
			// 释放资源
			typeArr.recycle();
		}
		if (!isShow) {
			icon.setVisibility(View.INVISIBLE);
		}

		name.setEnabled(isEdit);

	}

	public void setIconVisibility(int b) {
		icon.setVisibility(b);
	}

	public void setName(String names) {
		name.setText(names);
	}

	public void setTitle(String titles) {
		title.setText(titles);
	}

	public void setHint(String hint) {
		name.setHint(hint);
	}

	public void setError(String error) {
		name.setError(error);
	}

	public String getValue() {
		return name.getText().toString().trim();
	}

	public void setListener(OnFocusChangeListener listener) {
		name.setOnFocusChangeListener(listener);
	}
	
	public void setEditable(boolean f){
		name.setEnabled(f);
	}
}
